var webpack = require('webpack');
//var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var path = require('path');
var dirVars = require('../base/dir-vars.config.js');
var pageArr = require('../base/page-entries.config.js');

var configPlugins = [
    /* 全局shimming */
    new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        'window.$': 'jquery',
    }),
    /* 抽取出所有通用的部分 */
    new webpack.optimize.CommonsChunkPlugin({
        name: 'commons', // 需要注意的是，chunk的name不能相同！！！
        filename: '[name]/commons.js',
        minChunks: 0,
    }),
    /* 抽取出chunk的css */
    new ExtractTextPlugin({filename:'[name]/styles.css',allChunks:true}),
    /* 配置好Dll */
    new webpack.DllReferencePlugin({
        context: dirVars.staticRootDir, // 指定一个路径作为上下文环境，需要与DllPlugin的context参数保持一致，建议统一设置为项目根目录
        manifest: require('../../manifest.json'), // 指定manifest.json
        name: 'dll', // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下，注意与DllPlugin的name参数保持一致
    }),
    
    /*复制dll文件夹*/
    new CopyWebpackPlugin([
        { from: dirVars.dllDir, to: 'dll' },
        { from: dirVars.srcRootDir + '/index.html' },
    ])
];

/*pageArr.forEach((page) => {
  const htmlPlugin = new HtmlWebpackPlugin({
    filename: `${page}/page.html`,
    template: path.resolve(dirVars.pagesDir, `./${page}/html.js`),
    chunks: [page, 'commons/commons'],
    hash: true, // 为静态资源生成hash值
    xhtml: true,
  });
  configPlugins.push(htmlPlugin);
});*/

module.exports = configPlugins;